import type {
  PermissionItemType,
  QueryPermissionPayloadType,
  CreatePermissionPayloadType,
  UpdatePermissionPayloadType
} from '@/types/api/permission'
import Request from '@/utils/request'

export const getPermissionsApi = (data: QueryPermissionPayloadType) => {
  return Request.Get<PermissionItemType[]>({
    url: '/permissions',
    data
  })
}

export const getCurrentPermissionsApi = () => {
  return Request.Get<PermissionItemType[]>({
    url: '/permissions/me'
  })
}

export const createPermissionApi = (data: CreatePermissionPayloadType) => {
  return Request.Post({
    url: '/permission',
    data
  })
}

export const updatePermissionApi = (data: UpdatePermissionPayloadType) => {
  const { id, ...rest } = data
  return Request.Put({
    url: `/permission/${id}`,
    data: rest
  })
}

export const deletePermissionApi = (id: string) => {
  return Request.Delete({
    url: `/permission/${id}`
  })
}
